package firewing.object;

import java.io.Serializable;
import java.util.ArrayList;

import firewing.object.Dict.TrendSource;

/**
 * Keyword class represents the properties of hot-trend-keywords
 * 
 * @author Shuai Yuan
 */
public class Trend implements Serializable {
	private static final long serialVersionUID = 7025303511012236187L;

	// -----------common fields-----------------
	/**
	 * Google Trends? Baidu Top?
	 */
	private TrendSource _source;

	private String _phrase;

	/**
	 * position in the hot-trend list
	 */
	private int _rank;

	// -------------from Google Trends-----------

	private String _hotness;

	private ArrayList<String> _relatedSearch;

	/**
	 * when the keyword is the hottest
	 */
	private String _peak;

	private String _location;

	// ---------from Yahoo Buzz--------------
	private int _prevRank;

	private int _daysOnChart;

	private String _yahooBuzzMove;

	private int _yahooBuzzScore;

	private String _yahooBuzzOneDayMove;

	/**
	 * true = leader; false = mover;
	 */
	private boolean _yahooBuzzLeader;

	// ---------bidding related--------------

	private boolean _bidEstimation;

	private double _averageCPC;

	private double _dailyClick;

	private double _dailyCost;

	private double _bidPosition;

	public Trend() {

	}

	public Trend(String trend) {
		setPhrase(trend);
	}

	public Trend(Trend trend) {
		this._source = trend.getSource();
		this._phrase = trend.getPhrase();
		this._rank = trend.getRank();
		this._hotness = trend.getHotness();
		this._peak = trend.getPeak();
		this._location = trend.getLocation();
		this._averageCPC = trend.getAverageCPC();
		this._dailyCost = trend.getDailyCost();
		this._dailyClick = trend.getDailyClick();
		this._bidPosition = trend.getBidPosition();

		for (String s : trend.getRelatedSearch().split(",")) {
			addRelatedSearch(s);
		}
	}

	public void addRelatedSearch(String s) {
		if (_relatedSearch == null) {
			_relatedSearch = new ArrayList<String>();
		}

		_relatedSearch.add(s);
	}

	@Override
	public String toString() {
		// return getPhrase() + ", " + ranking + ", " + detailURL + ", " +
		// getHotness() + ", "
		// + getPeak() + ", " + getRelatedSearch().toString() + ", " +
		// getBidPosition()
		// + ", " + getAverageCPC() + ", " + getDailyClick() + ", " +
		// getDailyCost();
		String ret = "";
		ret += _phrase;
		ret += "\n";
		ret += _hotness;
		ret += "\n";
		ret += getRelatedSearch();

		return ret;
	}

	// -------------getters and setters----------------
	public void setSource(TrendSource _source) {
		this._source = _source;
	}

	public TrendSource getSource() {
		return _source;
	}

	public void setPhrase(String _phrase) {
		this._phrase = _phrase;
	}

	public String getPhrase() {
		return _phrase;
	}

	public void setRank(int _ranking) {
		this._rank = _ranking;
	}

	public int getRank() {
		return _rank;
	}

	public void setHotness(String _hotness) {
		this._hotness = _hotness;
	}

	public String getHotness() {
		return _hotness;
	}

	public void setRelatedSearch(String _relatedSearch) {
		for (String s : _relatedSearch.split(",")) {
			addRelatedSearch(s);
		}
	}

	public String getRelatedSearch() {
		String result = "";
		if (_relatedSearch != null) {
			for (int i = 0; i < _relatedSearch.size(); i++) {
				result += _relatedSearch.get(i);

				if (i != _relatedSearch.size() - 1) {
					result += ",";
				}
			}
		}
		return result;
	}

	public void setPeak(String _peak) {
		this._peak = _peak;
	}

	public String getPeak() {
		return _peak;
	}

	public void setLocation(String _location) {
		this._location = _location;
	}

	public String getLocation() {
		return _location;
	}

	public void setAverageCPC(double _averageCPC) {
		this._averageCPC = _averageCPC;
	}

	public double getAverageCPC() {
		return _averageCPC;
	}

	public void setDailyClick(double _dailyClick) {
		this._dailyClick = _dailyClick;
	}

	public double getDailyClick() {
		return _dailyClick;
	}

	public void setDailyCost(double _dailyCost) {
		this._dailyCost = _dailyCost;
	}

	public double getDailyCost() {
		return _dailyCost;
	}

	public void setBidPosition(double _bidPosition) {
		this._bidPosition = _bidPosition;
	}

	public double getBidPosition() {
		return _bidPosition;
	}

	public void setYahooBuzzOneDayMove(String _yahooBuzzOneDayMove) {
		this._yahooBuzzOneDayMove = _yahooBuzzOneDayMove;
	}

	public String getYahooBuzzOneDayMove() {
		return _yahooBuzzOneDayMove;
	}

	public void setYahooBuzzScore(int _yahooBuzzScore) {
		this._yahooBuzzScore = _yahooBuzzScore;
	}

	public int getYahooBuzzScore() {
		return _yahooBuzzScore;
	}

	public void setYahooBuzzMove(String _yahooBuzzMove) {
		this._yahooBuzzMove = _yahooBuzzMove;
	}

	public String getYahooBuzzMove() {
		return _yahooBuzzMove;
	}

	public void setDaysOnChart(int _daysOnChart) {
		this._daysOnChart = _daysOnChart;
	}

	public int getDaysOnChart() {
		return _daysOnChart;
	}

	public void setPrevRank(int _prevRank) {
		this._prevRank = _prevRank;
	}

	public int getPrevRank() {
		return _prevRank;
	}

	public void setYahooBuzzLeader(boolean _yahooBuzzLeader) {
		this._yahooBuzzLeader = _yahooBuzzLeader;
	}

	public boolean isYahooBuzzLeader() {
		return _yahooBuzzLeader;
	}

	public void setBidEstimation(boolean _biddingEstimation) {
		this._bidEstimation = _biddingEstimation;
	}

	public boolean hasBidEstimation() {
		return _bidEstimation;
	}
}
